﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace SIS_Wcf_Server
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class SisRestService
    {
        private SISServer _server;
        
        public SisRestService()
        {
            _server = new SISServer(new DefaultFactory());
        }


        [WebInvoke(UriTemplate = "Information/create", Method = "POST", ResponseFormat=WebMessageFormat.Json)]
        public Model.RestInformation CreateInformation(Model.RestInformation information)
        {
            return _server.CreateInformation(information);
        }



        [WebInvoke(UriTemplate = "Information/search/{filter}", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
        public List<Model.RestInformation> SearchInformation(List<Model.Lokation> locations, string filter)
        {
            return _server.GetInformationPackagesFromLocationSearch(locations);            
        }

        [WebGet(UriTemplate = "Information/all", ResponseFormat = WebMessageFormat.Json)]
        public List<Model.RestInformation> GetAllInformations()
        {
            return _server.GetInformations();
        }


        [WebGet(UriTemplate = "Location/all", ResponseFormat = WebMessageFormat.Json)]
        public List<Model.Lokation> GetAllLocations()
        {
            return _server.GetAllLocations();
        }

        [WebGet(UriTemplate = "Location/search")]
        public Model.ApproximatedPossistion Lookup()
        {
            Model.ApproximatedPossistion pos = new Model.ApproximatedPossistion();
            pos.accurcy = Model.AccurcyLevel.Metropolitian;
            pos.Lat = 2.1;
            pos.Lng = 2.0;
            pos.ArealDescription = "Close to africa";
            return pos;
        }


    }
}
